<template>
  <el-form :inline="true" @submit.native.prevent>
    <el-form-item>
      <el-radio-group v-model="queryParam.status" @change="handleQuery">
        <el-radio-button v-for="item in Dic.stockOrderStatus()"
                         :key="item.value"
                         :label="item.text"
                         :value="item.value"/>
      </el-radio-group>
    </el-form-item>
    <el-form-item>
      <el-date-picker v-model="queryParam.dateArray"
                      :shortcuts="Dic.DateShortcuts"
                      @change="handleQuery"
                      type="daterange"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      value-format="YYYY-MM-DD"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleQuery">搜索</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="tableData.list" v-loading="loading" border>
    <el-table-column label="单号" prop="ksn" min-width="100" align="center"/>
    <!--      <el-table-column label="产品名称" prop="goodsName" min-width="200" align="center"/>-->
    <el-table-column label="数量" prop="knum" width="90" align="center"/>
    <el-table-column label="金额" prop="kprice" min-width="120" align="center"/>
    <el-table-column label="待付金额" prop="ksyprice" min-width="120" align="center" :formatter="tableRed"/>
    <el-table-column label="状态" prop="kstatus" width="80" align="center" :formatter="Dic.stockOrderStatus"/>
  </el-table>
  <el-pagination layout="->,total,sizes,prev,pager,next,jumper"
                 v-model:current-page="queryParam.page"
                 v-model:page-size="queryParam.limit"
                 :total="tableData.total" background
                 @current-change="loadList"
                 @size-change="loadList"/>
</template>

<script lang="ts">
import supplierApi from "@/api/supplier";
import base from "@/utils/base";

export default {
  name: "inSheetList",
  mixins: [base],
  props: {
    query: {},
  },
  data() {
    return {
      visible: false,
      queryParam: {
        page: 1,
        limit: 10,
        supplierId: '',
        status: '',
        dateArray: []
      },
      tableData: {
        list: [],
        total: 0,
      },
      loading: false,
    };
  },
  watch: {
    query: {
      handler: function () {
        if (!this.query) {
          this.loadList()
          return
        }
        let {supplierId, dateArray, status} = this.query
        if (supplierId) {
          this.queryParam = {...this.queryParam, supplierId, dateArray, status};
          this.loadList();
        }
      },
      deep: true,
      immediate: true
    },
  },

  methods: {
    handleQuery() {
      this.queryParam.page = 1;
      this.loadList();
    },
    loadList() {
      this.loading = true;
      supplierApi.inSheetList(this.queryParam).then(res => {
        this.loading = false;
        this.tableData = res.data
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.cell-item {
  display: flex;
  align-items: center;
}
</style>